package com.project.service.impl;

import com.project.bean.FacilitiesBean;
import com.project.bean.RoomBean;

import com.project.mapper.IFacilitiesMapper;
import com.project.mapper.IRoomMapper;
import com.project.service.IFacilitiesService;
import com.project.service.IRoomService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class FacilitiesServiceImpl implements IFacilitiesService {
    @Autowired
    private IFacilitiesMapper mapper;
    @Autowired
    private IRoomMapper rMapper;

  @Override
  public List<FacilitiesBean> findByRoomId(Integer roomId) {
    return mapper.findByRoomId(roomId);
  }

  @Override
  public void updateState(Integer id, Integer roomId) {
      FacilitiesBean facilitiesBean = new FacilitiesBean();
      facilitiesBean.setId(id);
      facilitiesBean.setDamageState("已解决");
      mapper.updateById(facilitiesBean);
     int num = mapper.findFacilitiesNum(roomId,"未解决");
     if (num==0){
         RoomBean room = new RoomBean();
         room.setId(roomId);
         room.setRoomState("正常");
       rMapper.updateById(room);
     }
  }

  @Override
  public void add(FacilitiesBean facilities) {
    mapper.insert(facilities);
      RoomBean room = new RoomBean();
      room.setId(facilities.getRoomBean().getId());
      room.setRoomState("设施损坏");
      rMapper.updateById(room);
  }
  }
